import { Component, OnInit } from '@angular/core';
import { NzModalRef, NzMessageService } from 'ng-zorro-antd';
import { _HttpClient } from '@delon/theme';
import { CommonService } from '../../../../core/service/common.service';

@Component({
  selector: 'app-sys-type-type-modal',
  templateUrl: './type-modal.component.html',
})
export class SysTypeTypeModalComponent implements OnInit {
  url = '';
  urlTree = '';
  i: any;
  nodes: any[] = [];

  constructor(private modal: NzModalRef, public msgSrv: NzMessageService, public http: _HttpClient, public commonService: CommonService ) { }

  ngOnInit(): void {
    this.url =  `${this.commonService.getServerPath()}api/sysType`;
    this.urlTree =  `${this.commonService.getServerPath()}api/sysTypeTree`;
    this.i = Object.assign({}, this.i);
    this.loadTree();
  }

  loadTree() {
    let me = this;
    me.http.get(this.urlTree).subscribe((succ: any) => {
      me.nodes = succ;
    });
  }

  save() {
    this.http.post(this.url,this.i).subscribe((succ) => {
      this.modal.close(true);
      this.close();
    });
  }

  close() {
    this.modal.destroy();
  }
}
